package io.renren.modules.health.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.modules.health.dao.FoodDao;
import io.renren.modules.health.dto.FoodDTO;
import io.renren.modules.health.entity.FoodEntity;
import io.renren.modules.health.service.FoodService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 食品表
 *
 * @author Mark 
 * @since 1.0.0 2024-03-24
 */
@Service
public class FoodServiceImpl extends CrudServiceImpl<FoodDao, FoodEntity, FoodDTO> implements FoodService {

    @Override
    public QueryWrapper<FoodEntity> getWrapper(Map<String, Object> params){
        String id = (String)params.get("id");
        String foodName = (String)params.get("foodName");
        String planDayTime = (String)params.get("planDayTime");
        List<Long> foodIds = (List<Long>) params.get("foodIds");
        Double bmi = (Double) params.get("bmi");

        QueryWrapper<FoodEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);
        wrapper.in(!Objects.isNull(foodIds) && !foodIds.isEmpty(),"id",foodIds);
        wrapper.like(StrUtil.isNotBlank(foodName),"food_name",foodName);
        wrapper.eq(StrUtil.isNotBlank(planDayTime),"plan_day_time",planDayTime);
        wrapper.lt(bmi != null, "start_bmi", bmi).gt(bmi != null, "end_bmi", bmi);
        return wrapper;
    }


}